-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] Fast tileCount with help from @mapbox/sphericalmercator module #9906
Conversation
2fba28f
to
65c1d27
Compare
assert(maxZ < std::numeric_limits<uint8_t>::max()); | ||
|
||
unsigned long result = 0;; | ||
for (auto z = minZ; z <= maxZ; z++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto
→ uint8_t
@@ -43,6 +44,24 @@ std::vector<CanonicalTileID> OfflineTilePyramidRegionDefinition::tileCover(Sourc | |||
return result; | |||
} | |||
|
|||
unsigned long OfflineTilePyramidRegionDefinition::tileCount(SourceType type, uint16_t tileSize, const Range<uint8_t>& zoomRange) const { | |||
double minZ = std::max<double>(util::coveringZoomLevel(minZoom, type, tileSize), zoomRange.min); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refactor the code that's duplicated from tileCover
into a function with the signature:
Range<uint8_t> coveringZoomRange(SourceType, uint16_t tileSize, const Range<uint8_t>& zoomRange) const
|
||
unsigned long result = 0;; | ||
for (auto z = minZ; z <= maxZ; z++) { | ||
auto count = util::tileCount(bounds, z, tileSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result += util::tileCount(bounds, z, tileSize)
@@ -89,6 +89,19 @@ class Projection { | |||
wrapMode | |||
}; | |||
} | |||
|
|||
// Project lat, lon to point in a zoom-dependent world size | |||
static Point<double> project(const LatLng& point, uint8_t zoom, uint16_t tileSize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be written in terms of the existing project
function, or vice versa?
8ddd56a
to
0d732cb
Compare
assert(maxZ >= 0); | ||
assert(minZ < std::numeric_limits<uint8_t>::max()); | ||
assert(maxZ < std::numeric_limits<uint8_t>::max()); | ||
return { (uint8_t)minZ, (uint8_t)maxZ }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use static_cast
rather than C-style cast.
0d732cb
to
9b19ab7
Compare
@@ -18,5 +18,8 @@ int32_t coveringZoomLevel(double z, SourceType type, uint16_t tileSize); | |||
std::vector<UnwrappedTileID> tileCover(const TransformState&, int32_t z); | |||
std::vector<UnwrappedTileID> tileCover(const LatLngBounds&, int32_t z); | |||
|
|||
// Compute only the count of tiles needed for tileCover | |||
unsigned long tileCount(const LatLngBounds&, uint8_t z, uint16_t tileSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please use fixed width number types (like uint64_t
)? Unfortunately, unsigned long
is 32 bit on some and 64 bit on other platforms.
Closes #9675
Implement a separate
util::tileCount()
method for computing the number of tiles that need to be downloaded for offline packs.The time for computing tile count for a bounding box around SF went from 12070 ms to 1 ms.
The failed attempts include:
tileCover
on the max zoom, and getting parents of those tiles up to min zoom. I was surprised by the cost ofboost::hash_combine
which made this more expensive than runningtileCover
for every zoom level.LatLng
extents of the bounding box vsLatLng
extents of a tile. This approached had way better performance but suffered from floating point errors due to the precision ofLatLng
for high zoom levels.Thanks to @jfirebaugh for pointing me to @mapbox/sphericalmercator